layui.use('table', function(){
    var table = layui.table;
    var delurl = "/general/erp5/public/tripapi/negotiation/ChatDelete";
    //方法级渲染
    table.render({
        elem: '#apply_list'
        ,url: '/general/erp5/public/tripapi/negotiation/GetList'
        ,response: {
             statusName: 'status'
            ,statusCode: 200
            ,msgName: 'msg'
            ,countName: 'count'
            ,dataName: 'data'
        }
        ,cols: [[
            {checkbox: true, fixed: true}
            ,{field:'id', title: 'ID', width: 70}
            ,{field:'category', title: '分类', width: 150}
            ,{field:'order_id', title: '项目单号',width: 150}
            ,{field:'chat_num', title: '会议纪要单号',width: 150}
            ,{field:'write_time', title: '日期', width: 150}
            ,{field:'apply_num', title: '出差申请单号', width: 150}
            ,{field:'customer_type', title: '客户类型', width: 150}
            ,{field:'customer_src', title: '客户来源', width: 150}
            ,{field:'company', title: '客户公司名称', width: 150}
            ,{field:'customer_category', title: '客户类别', width: 150}
            ,{field:'customer_trade', title: '客户行业',width: 150}
            ,{field:'customer_place', title: '客户区域',width: 150}
            ,{field:'talk_type', title: '洽谈形式',width: 150}
            ,{field:'talk_time', title: '洽谈时间',width: 150}
            ,{field:'salers', title: '销售人员',width: 150}
            ,{field:'cooper_user', title: '协作人',width: 150}
            ,{field:'talk_num', title: '洽谈次数',width: 150}
            ,{field:'contact1', title: '第一联系人',width: 150}
            ,{field:'contact1_job', title: '第一联系人职位',width: 150}
            ,{field:'contact1_tel', title: '第一联系人电话',width: 150}
            ,{field:'customer_address', title: '客户地址',width: 150}
            ,{field:'contact2', title: '第二联系人',width: 150}
            ,{field:'contact2_job', title: '第二联系人职位',width: 150}
            ,{field:'contact2_tel', title: '第二联系人电话',width: 150}
            ,{field:'customer_all', title: '客户洽谈全部参与人员',width: 220}
            ,{field:'staff_all', title: '永冠洽谈全部参与人员',width: 220}
            ,{field:'subject', title: '洽谈主题',width: 220}
            ,{field:'content1', title: '技术问题(主要内容)',width: 220}
            ,{field:'content2', title: '供应情况(洽谈中遇到的主要问题)',width: 220}
            ,{field:'content3', title: '合作方式(需要公司的支持)',width: 220}
            ,{field:'content4', title: '其他商谈内容',width: 220}
            ,{field:'report_user', title: '报告编制人',width: 150}
            ,{field:'creator', title: '创建人',width: 150}
            ,{field:'create_time', title: '创建时间',width: 150}
            ,{field:'department', title: '非销售人员洽谈部门',width: 150}
            ,{field:'talk_place', title: '非销售人员洽谈地点',width: 150}
            ,{field:'', title: '操作', toolbar:'#tab1Bar',width: 200,fixed: 'right'}
        ]]
        ,id: 'testReload'
        ,page: true
        ,toolbar:"#tab2Bar"
        ,text: { none: '暂无相关数据' }
    });
    table.on('tool(user)', function (obj) {
        switch(obj.event){
            // case 'show':
            //     location.replace("/general/erp5/public/tripapi/negotiation/travelsalershow?id=" + obj.data.id);
            //     break;
            // case 'edit':
            //     location.replace("/general/erp5/public/tripapi/negotiation/travelsaleredit?id=" + obj.data.id);
            //     break;
            case 'del':
                layer.confirm('该操作不可恢复. 确定删除?', {icon: 3, title: '提示'}, function (index) {
                    $.ajax({
                        type: "POST",
                        url: delurl+"?id="+obj.data.id,
                        traditional: true, //是否使用传统的方式浅层序列化,若有数组参数或对象参数需要设置true!!!!!!
                        dataType:"json",
                        success: function(returnData){
                            if(returnData.status == 200){
                                obj.del();
                                layer.close(index);
                            }else{
                                layer.open({
                                    type: 1
                                    ,offset: 'auto'
                                    ,id: 'layerDemo'
                                    ,content: '<div style="padding: 20px 100px;">'+ returnData.msg +'</div>'
                                    ,btn: '确定'
                                    ,btnAlign: 'c'
                                    ,shade: 0
                                    ,yes: function(){
                                        layer.closeAll();
                                    }
                                });
                            }
                        }
                    })
                });
        }
    })
    table.on('toolbar(user)', function (obj) {
        switch(obj.event){
            case 'saleradd':
                location.replace("/general/erp5/public/tripapi/negotiation/travelsaler");
                break;
            case 'notsaleradd':
                location.replace("/general/erp5/public/tripapi/negotiation/travelnotsaler");
                break;
        }

    })
    var $ = layui.$, active = {
        reload: function(){
            var demoReload = $('#idreload');
            //执行重载
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    key: {
                        id: demoReload.val()
                    }
                }
            }, 'data');
        }
    };

    $('.apply_table .layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
});